﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sys.WebRes.Data
{
    public partial class ResAttachLinkType
    {
        public static Dictionary<int, ResAttachLinkType> Map = new Dictionary<int, ResAttachLinkType>();

        public static ResAttachLinkType Thumbnail = new ResAttachLinkType(1, "缩略图", "Thumbnail", "资源缩略图", 1);
        public static ResAttachLinkType Quote = new ResAttachLinkType(2, "引用", "Quote", "在文章类资源中被引用", 2);
        public static ResAttachLinkType Content = new ResAttachLinkType(3, "内容", "Content", "在媒体集，图文集和文件集资源中作为正文内容", 3);

        public static void Initialize(ResourceSysEntities db)
        {
            var list = db.ResAttachLinkTypeTBL.ToList();
            if (list.Count > 0)
            {
                list.ForEach(p =>
                {
                    Map[p.ID].Name = p.Name;
                    Map[p.ID].Abbr = p.Abbr;
                    Map[p.ID].Explain = p.Explain;
                    Map[p.ID].OrderNo = p.OrderNo;
                });
            }
            else
            {
                Array.ForEach(Map.Values.ToArray(), p =>
                {
                    db.AddToResAttachLinkTypeTBL(p);
                });
            }
        }

        private ResAttachLinkType(int id, string name, string abbr, string explain, int orderNo)
        {
            this.ID = id;
            this.Name = name;
            this.Abbr = abbr;
            this.Explain = explain;
            this.OrderNo = orderNo;

            Map.Add(id, this);
        }

        public ResAttachLinkType() { }
    }
}
